package action.chap6;

import action.chap5.Trader;
import action.chap5.Transaction;
import action.chap5.TransactionUtils;

import java.util.*;

import static java.util.stream.Collectors.groupingBy;


public class Demo61 {
    public static void main(String[] args) {
        List<Transaction> transactions = TransactionUtils.getData();

        Map<Trader, List<Transaction>> transactionsByCurrencies =
                new HashMap<>();
        for (Transaction transaction : transactions) {
            Trader trader = transaction.getTrader();
            List<Transaction> transactionsForCurrency =
                    transactionsByCurrencies.get(trader);
            if (transactionsForCurrency == null) {
                transactionsForCurrency = new ArrayList<>();
                transactionsByCurrencies
                        .put(trader, transactionsForCurrency);
            }
            transactionsForCurrency.add(transaction);
        }

        transactions.stream().collect(groupingBy(Transaction::getTrader));

    }
}
